/**
* labSpecChart functions
* copyright@Catosoft.com reserved, 2016
* 2016.07.30, created by Eric.Wang
*/



/*
* get data
*/
var getLabSpecData = function(){
	var data = {

	};
	var option = {
		url: '/draft/lab/spec/v1',
		type: 'GET',
		data: data,
	};
	createAjax(option, function(err, res){
		if(!err){
			labSpecScatterChart('labSpecScatterChart', res);
			labSpecTable('labSpecTable', res);
		}
	});
}

/*
* data filter
*/
var labSpecScatterChartFilter = function(data){
	var series = [{
		name: 'ALT',
		identifier: 'alt',
		data: [],
	}, {
		name: 'AST',
		identifier: 'ast',
		data: [],
	}, {
		name: 'TBIL',
		identifier: 'tbil',
		data: [],
	}, {
		name: 'DBIL',
		identifier: 'dbil',
		data: [],
	}];
	var categories = [];
	columnFilter(data, series, categories);
	return {
		series: series,
		categories: categories,
	};
}

/*
* draw charts
*/
var labSpecScatterChart = function(element, data){
	var filter = labSpecScatterChartFilter(data.list);
	var labSpecScatterChartOption = {
		chart: {
	        type: 'scatter',
	        renderTo: element,
	        zoomType: 'x'
	    },
	    colors: colors[0],
		title: {
	        text: chartTitles.labSpecChart,
	    },
	    xAxis: {
	    	title: {
	    		text: '中心',
	    	},
	    	type: 'category',
	    	categories: filter.categories,
	    },
	    yAxis: {
	        title: {
	            text: '',
	        },
	        plotLines: [{
	            value: 0,
	            width: 1,
	            color: '#808080'
	        }]
	    },
	    legend: {
	        layout: 'vertical',
	        align: 'right',
	        verticalAlign: 'middle',
	        borderWidth: 0
	    },
	    series: filter.series,
	    credits: credits,
	    exporting: {
	    	buttons: {
	    		contextButton: {
	    			menuItems: getMenuItems(),
	    		}
	    	}
	    },
	};
	var chart = new Highcharts.Chart(labSpecScatterChartOption);
	
	bindSelect(element, chart, filter);
}

var labSpecTable = function(element, data){
	$('#' + element).bootstrapTable({
		data: data.list,
		classes: 'table table-hover',
		pagination: false,
		pageSize: 20,
		pageNumber: 1,
		pageList: [20, 50],
		sidePagination: 'client',
		showRefresh: true,
		showColumns: true,
		buttonsAlign: 'right',
		showExport: true,
		exportDataType: 'all',
		exportTypes: ['csv', 'txt', 'excel'],
		locale: 'zh-CN',
		columns: [
		{
			field: 'Number',  
	    title: '序号',  
	    formatter: function (value, row, index) {  
	    	return index + 1;  
	    }
		},
		{
			title: '中心',
			field: 'pursuercodes',
		}, {
			title: 'ALT',
			field: 'alt',
		}, {
			title: 'AST',
			field: 'ast',
		}, {
			title: 'TBIL',
			field: 'tbil',
		}, {
			title: 'DBIL',
			field: 'dbil',
		}],

	});
}

$(function(){
	getLabSpecData();
});